# Translation Editor Startup Script (Dependencies should be installed first)

Write-Host "=== Translation Editor Startup Script ===" -ForegroundColor Green

# Check if node_modules exists
if (!(Test-Path "node_modules")) {
    Write-Host "Frontend dependencies not found. Please run: npm install" -ForegroundColor Red
    Read-Host "Press any key to exit"
    exit 1
}

if (!(Test-Path "server/node_modules")) {
    Write-Host "Backend dependencies not found. Please run: cd server && npm install" -ForegroundColor Red
    Read-Host "Press any key to exit"
    exit 1
}

Write-Host "=== Starting Translation Editor ===" -ForegroundColor Green

# Start backend server
Write-Host "Starting backend server (port 3001)..." -ForegroundColor Yellow
Start-Process PowerShell -ArgumentList "-NoExit", "-Command", "cd '$PWD/server'; npm start"

# Wait for backend to start
Write-Host "Waiting for backend server to start..." -ForegroundColor Yellow
Start-Sleep -Seconds 3

# Start frontend development server
Write-Host "Starting frontend server (port 3000)..." -ForegroundColor Yellow
Start-Process PowerShell -ArgumentList "-NoExit", "-Command", "cd '$PWD'; npm run dev"

Write-Host "=== Servers Starting ===" -ForegroundColor Green
Write-Host ""
Write-Host "Local access:" -ForegroundColor Cyan
Write-Host "  Frontend: http://localhost:3000" -ForegroundColor Cyan
Write-Host "  Backend:  http://localhost:3001" -ForegroundColor Cyan
Write-Host ""
Write-Host "LAN access (other devices):" -ForegroundColor Cyan
Write-Host "  Frontend: http://192.168.9.104:3000" -ForegroundColor Cyan
Write-Host "  Backend:  http://192.168.9.104:3001" -ForegroundColor Cyan
Write-Host ""
Write-Host "Features:" -ForegroundColor Yellow
Write-Host "  - Search by Chinese text or ID" -ForegroundColor White
Write-Host "  - Scroll up/down for infinite loading" -ForegroundColor White
Write-Host "  - Max 40 items displayed (performance optimized)" -ForegroundColor White
Write-Host "  - Individual save buttons for each item" -ForegroundColor White
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor Green
Read-Host 